package com.kawins.supers.message.socket.listener;

import com.kawins.supers.message.socket.bean.SocketMessage;
import org.springframework.data.redis.connection.DefaultMessage;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;

import java.io.Serializable;

/**
 * @author rankai
 *         createTime 2018-01-2018/1/22 18:29
 */
public class MessageBean extends DefaultMessage {

    private JdkSerializationRedisSerializer redisSerializer = new JdkSerializationRedisSerializer();

    public final MessageBody msgBody;

    public MessageBean(byte[] channel, byte[] body) {
        super(channel, body);
        msgBody = (MessageBody) redisSerializer.deserialize(body);
    }

    public static class MessageBody implements Serializable {

        public final String serverName;
        public final Integer type;
        public final Serializable key;
        public final Serializable sessionId;
        public final SocketMessage socketMessage;

        public MessageBody(String serverName, Integer type, Serializable key, Serializable sessionId, SocketMessage socketMessage) {
            this.serverName = serverName;
            this.type = type;
            this.key = key;
            this.sessionId = sessionId;
            this.socketMessage = socketMessage;
        }

        @Override
        public String toString() {
            return "MessageBody{" +
                    "serverName='" + serverName + '\'' +
                    ", type=" + type +
                    ", key='" + key + '\'' +
                    ", socketMessage=" + socketMessage +
                    '}';
        }
    }
}